{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
  <form class="layui-form gg-form-bar border-t border-x">
    <div class="layui-input-inline" style="width:300px;">
      <input type="text" name="keywords" placeholder="昵称/手机号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:120px;">
      <input type="text" class="layui-input" id="start_time" readonly placeholder="注册开始时间" name="start_time">
    </div>
    ~
    <div class="layui-input-inline" style="width:120px;">
      <input type="text" class="layui-input" id="end_time" readonly placeholder="注册结束时间" name="end_time">
    </div>
    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">提交搜索</button>
  </form>
  <table class="layui-hide" id="user" lay-filter="user"></table>
</div>
<div class="row col-sm-12" style="display:none;" id="show_divs">
  <form class="layui-form model-form" lay-filter="submitForm3">
    <div class="layui-inline" style="margin-top: 20px">
      <label class="layui-form-label">操作：</label>
      <div class="layui-input-inline">
        <input type="radio" name="types" value="1" title="增加" class="dan" checked>
        <input type="radio" name="types" value="2" title="减少" class="dan">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">数量：</label>
      <div class="layui-input-inline">
        <input type="text" name="e_score" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item" style="margin-left: 109px;margin-top: 20px;">
      <div class="layui-inline">
        <button class="layui-btn">提交</button>
      </div>
    </div>
  </form>
</div>
<script type="text/html" id="status">
  <i class="layui-icon {{#  if(d.status == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
  const moduleInit = ['tool'];
  function gouguInit() {
    var tool = layui.tool, table = layui.table, laydate = layui.laydate, form = layui.form;
    laydate.render({
      elem: '#start_time',
      type: 'date'
    });

    laydate.render({
      elem: '#end_time',
      type: 'date'
    });

    layui.pageTable = table.render({
      elem: '#user',
      title: '用户列表',
      toolbar: '#toolbarDemo',
      url: '/admin/user/indexs', //数据接口
      page: true, //开启分页
      limit: 20,
      cols: [
        [ //表头
          {
            field: 'id',
            title: 'ID号',
            align: 'center',
            width: 80
          }, {
          field: 'avatar',
          title: '头像',
          align: 'center',
          width: 60,
          templet: function (d) {
            var html = '';
            var delBtn = '<img src="' + d.avatar + '" width="28" height="28"/>';
            return delBtn;
          }
        }, {
          field: 'nickname',
          title: '昵称',
          align: 'center',
          width: 200
        }, {
          field: 'mobile',
          title: '手机号码',
          align: 'center',
          width: 200
        }, {
          field: 'user_type',
          title: '用户身份',
          align: 'center',
          width: 130,
          templet: function (d) {
            var str = "";
            if (d.user_type == 0) {
              str = '<span>未注册</span>';
            } else if(d.user_type == 1) {
              str = '<span style="color: #5FB878">个人</span>';
            } else {
              str = '<span style="color: #01a0e4">企业</span>';
            }
            return str;
          },
        }, {
          field: 'register_time',
          title: '注册时间',
          align: 'center',
          width: 180
        }, {
          field: 'right',
          fixed: 'right',
          title: '操作',
          align: 'center',
          width: 156,
          templet:function(d){
            let btn1 = '<span class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">详情</span>';
            // <span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>;
            // let btn2 = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</span>';
            // let btn3 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="open">启用</span>';
            return '<div class="layui-btn-group">'+btn1+'</div>';
          }
        }
        ]
      ]
    });

    //监听行工具事件
    table.on('tool(user)', function (obj) {
      var data = obj.data;
      if (obj.event === 'view') {
        tool.side('/admin/user/view?id=' + data.id);
        return;
      }
      else if (obj.event === 'bi') {
        tool.side('/admin/score_log/datalist?id=' + data.id);
        return;
      }
      else if (obj.event === 'team') {
        tool.side('/admin/user/team?id=' + data.id);
        return;
      }
      else if (obj.event === 'edit') {
        tool.side('/admin/user/edit?id=' + data.id);
        return;
      }
      else if (obj.event === 'bu') {
        var id = data.id;
        var user_score = $(this).data('wallet');
        var index = layer.open({
          type: 1,
          title: ['积分 账户调整'],//数组第二项可以写任意css样式；如果你不想显示标题栏，你可以title: false
          area: '500px',
          content: $('#show_divs'),
          success:function(){
            $('.bi').text(user_score);
            form.on('submit(submitForm3)', function (data) {
              var types = $("input[name='types']:checked").val();
              var escore = $("input[name='e_score']").val();
              let inx = layer.load(0, {shade: [0.4, '#000']});
              $.post('/admin/user/bu', {type:types,id:id,score:escore}, function(res) {
                if (res.code == 1) {
                  layer.msg(res.msg,{icon:0,time:1500},function () {
                    layer.closeAll();
                  });
                } else {
                  layer.closeAll();
                  layer.msg('操作成功',{icon:1,time:1500},function(){
                    window.parent.$(".layui-icon-refresh").click();
                  });
                }
              },'json');
              return false;
            });
          }
        })
        return;
      }
      else if (obj.event === 'del') {
        layer.confirm('您确定要禁用该用户', {
          icon: 3,
          title: '提示'
        }, function (index) {
          let callback = function (e) {
            layer.msg(e.msg);
            if (e.code == 0) {
              layer.close(index);
              layui.pageTable.reload()
            }
          }
          tool.post("/admin/user/disable", { id: data.id, status: 0 }, callback);
          layer.close(index);
        });
      } else if (obj.event === 'open') {
        layer.confirm('您确定要启用该用户', {
          icon: 3,
          title: '提示'
        }, function (index) {
          let callback = function (e) {
            layer.msg(e.msg);
            if (e.code == 0) {
              layer.close(index);
              layui.pageTable.reload()
            }
          }
          tool.post("/admin/user/disable", { id: data.id, status: 1 }, callback);
          layer.close(index);
        });
      }
    });
    //监听搜索提交
    form.on('submit(webform)', function (data) {
      layui.pageTable.reload({
        where: {
          keywords: data.field.keywords,
          attach: data.field.attach,
          start_time: data.field.start_time,
          end_time: data.field.end_time
        },
        page: {
          curr: 1
        }
      });
      return false;
    });
  }
</script>
{/block}
<!-- /脚本 -->